package cn.zptc.springbootdemo.config;

import cn.zptc.springbootdemo.component.MyFilter;
import cn.zptc.springbootdemo.component.MyListener;
import cn.zptc.springbootdemo.component.MyServlet;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;

/**
 * @author ：zhaoweiwei
 * @date ：创建于 2025/3/10 14:17
 * @description：
 * @modified By：
 * @version: 1.0.0
 */
//@Configuration
public class ServletConfig {

    @Bean
    public ServletRegistrationBean getServlet(MyServlet myServlet){

        return new ServletRegistrationBean(myServlet,"/servlet1","/servlet2");
    }

    //@Bean
    public FilterRegistrationBean getFilter(MyFilter myFilter){

        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        filterRegistrationBean.setFilter(myFilter);
        filterRegistrationBean.setUrlPatterns(Arrays.asList("/filter1","/filter2"));

        return filterRegistrationBean;
    }

    @Bean
    public ServletListenerRegistrationBean getListener(MyListener myListener){
        ServletListenerRegistrationBean servletListenerRegistrationBean = new ServletListenerRegistrationBean(myListener);
        return servletListenerRegistrationBean;
    }
}
